﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_ViewMenu.cshtml";
}
<script src="~/Content/BootstrapSouce/js/bootstrap.js"></script>
<script src="~/Content/BootstrapSouce/js/Common.js"></script>
<script src="~/Content/BootstrapSouce/js/myAlert.js"></script>

<!-- 当前位置 -->
<div id="urHere">DouPHP 管理中心<b>&gt;</b><strong>挂号信息</strong> </div>
<div style="width:100%">
    <div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">

        <div style="width:70%;float:left">
            <h3>挂号信息</h3>
            <form action="product_category.php?rec=insert" method="post">
                <table width="100%" class="table table-bordered  tableBasic">
                    <thead>
                        <tr>
                            <th width="20" align="center"></th>
                            <th align="center">状态</th>
                            <th align="center">姓名</th>
                            <th align="center">性别</th>
                            <th align="center">年龄</th>
                            <th align="center">科室</th>
                            <th align="center">医生</th>
                            <th align="center">挂号员</th>
                            <th align="center">挂号时间</th>
                        </tr>
                    </thead>
                    <tbody id="tbodyShow"></tbody>
                    <tfoot>
                        <tr>
                            <td colspan="9" class="divPage"></td>
                        </tr>
                    </tfoot>
                </table>
            </form>
        </div>
        <div style="width:25%;float:left;padding:0 20px">
            <h3>新增挂号</h3>
            <table width="100%" class="table table-bordered tableBasic">
                <tbody>
                    <tr>
                        <td width="60" align="right" style="padding:8px 2px">序号</td>
                        <td>
                            <label id="RegistId"></label>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="padding:8px 2px">姓名</td>
                        <td>
                            <input type="text" id="RegistChiName" name="RegistChiName" value="" size="22" class="inpMain">
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="padding:8px 2px">性别</td>
                        <td>
                            <input type="radio" name="RegistSex" value="1" size="22" />男
                            <input type="radio" name="RegistSex" value="2" size="22" />女
                        </td>
                    </tr>

                    <tr>
                        <td align="right" style="padding:8px 2px">年龄</td>
                        <td>
                            <input type="text" id="RegistAge" name="RegistAge" value="" size="22" class="inpMain">
                        </td>
                    </tr>

                    <tr>
                        <td align="right" style="padding:8px 2px">科室</td>
                        <td>
                            <select id="DepartId" onchange="DepartInfoChange(this)" name="RegistTypeId">
                                <option>
                                    请选择
                                </option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="padding:8px 2px">医生</td>
                        <td>
                            <select id="UserIdOne" name="RegistTypeId">
                                <option>
                                    请选择
                                </option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="padding:8px 2px">挂号类型</td>
                        <td>
                            <select id="RegistTypeId" onchange="RegistTypeChange(this)" name="RegistTypeId">
                                <option>
                                    请选择
                                </option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="padding:8px 2px">应收金额</td>
                        <td>
                            <span style="display:inline-block;width:115px" id="RegistRePrice"></span>元
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="padding:8px 2px">优惠金额</td>
                        <td>
                            <input type="text" style="width:100px" id="RegistNoPrice" name="RegistNoPrice" value="50" size="22" class="inpMain">
                            元
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="padding:8px 2px">实收金额</td>
                        <td>
                            <span style="display:inline-block;width:115px" id="RegistHasPrice"></span>元
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <input type="hidden" name="token" value="b9439ae8">
                            <input type="hidden" name="cat_id" value="">
                            <input class="btn" id="btnSave" type="button" value="挂号收费">
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

</div>
<div class="clear"></div>
<script>
    $(function () {
        $("#btnSave").click(function () {
            $.ajax({
                type: "POST",
                url: "/RegistType/FnGetRegistTypeModel",
                data: {
                    RegistTypeId: $("#RegistTypeId").val()
                },
                success: function (data) {
                    if ($("#RegistId").html() == "") {
                        var RegistChiName = $("#RegistChiName").val();
                        var RegistSex = $("input[name=RegistSex]:checked").val();
                        var RegistAge = $("#RegistAge").val();
                        var DepartId = $("#DepartId").val();
                        var UserIdOne = $("#UserIdOne").val();
                        var RegistTypeId = $("#RegistTypeId").val();
                        var RegistNoPrice = $("#RegistNoPrice").val();
                        var RegistHasPrice = 0;
                        $("#RegistRePrice").html(data.RegistTypeSalePrice);
                        RegistHasPrice = parseFloat(data.RegistTypeSalePrice) - parseFloat(RegistNoPrice);
                        $("#RegistHasPrice").html(RegistHasPrice);
                        $.ajax({
                            type: "POST",
                            url: "/RegistInfo/FnRegistInfoAdd",
                            data: {
                                RegistChiName: RegistChiName,
                                RegistSex: RegistSex,
                                RegistAge: RegistAge,
                                DepartId: DepartId,
                                UserIdOne: UserIdOne,
                                RegistTypeId: RegistTypeId,
                                RegistNoPrice: RegistNoPrice,
                                RegistHasPrice: RegistHasPrice,
                                RegistRePrice: data.RegistTypeSalePrice
                            },
                            success: function (IsSuccess) {
                                if (IsSuccess) {
                                    MyAlert("提示", "初始化成功", "确认", false, "success")
                                } else {
                                    MyAlert("提示", "初始化失败", "确认", false, "warning")
                                }
                            }
                        })
                    } else {
                        var RegistId = $("#RegistId").html();
                        var RegistChiName = $("#RegistChiName").val();
                        var RegistSex = $("input[name=RegistSex]:checked").val();
                        var RegistAge = $("#RegistAge").val();
                        var DepartId = $("#DepartId").val();
                        var UserIdOne = $("#UserIdOne").val();
                        var RegistTypeId = $("#RegistTypeId").val();
                        var RegistNoPrice = $("#RegistNoPrice").val();
                        var RegistHasPrice = 0;
                        $("#RegistRePrice").html(data.RegistTypeSalePrice);
                        RegistHasPrice = parseFloat(data.RegistTypeSalePrice) - parseFloat(RegistNoPrice);
                        $("#RegistHasPrice").html(RegistHasPrice);
                        $.ajax({
                            type: "POST",
                            url: "/RegistInfo/FnRegistInfoUpt",
                            data: {
                                RegistChiName: RegistChiName,
                                RegistSex: RegistSex,
                                RegistAge: RegistAge,
                                DepartId: DepartId,
                                UserIdOne: UserIdOne,
                                RegistTypeId: RegistTypeId,
                                RegistNoPrice: RegistNoPrice,
                                RegistHasPrice: RegistHasPrice,
                                RegistRePrice: data.RegistTypeSalePrice,
                                RegistId: RegistId
                            },
                            success: function (IsSuccess) {
                                if (IsSuccess) {
                                    MyAlert("提示", "初始化成功", "确认", false, "success")
                                } else {
                                    MyAlert("提示", "初始化失败", "确认", false, "warning")
                                }
                            }
                        })
                    }
                }
            })

        })
    })

</script>
<script>
    $(function () {  //添加页面的Ajax
        $.ajax({//Ajax生成挂号类型下拉框
            type: "POST",
            url: "/RegistType/FnRegistTypeList",
            success: function (data) {
                var SelectDemo = new Array();
                SelectDemo.push(" <option value=\"0\">请选择</option>")
                for (var i = 0; i < data.length; i++) {
                    SelectDemo.push("")
                    SelectDemo.push(" <option value=\"")
                    SelectDemo.push(data[i].RegistTypeId)
                    SelectDemo.push("\">")
                    SelectDemo.push(data[i].RegistTypeName)
                    SelectDemo.push("</option>")
                }
                $("#RegistTypeId").html(SelectDemo.join(""))
            }
        })
        $.ajax({//Ajax生成挂号科室下拉框
            type: "POST",
            url: "/DepartInfo/FnDepartInfoList",
            success: function (data) {
                var SelectDemo = new Array();
                SelectDemo.push(" <option value=\"0\">请选择</option>")
                for (var i = 0; i < data.length; i++) {
                    SelectDemo.push("")
                    SelectDemo.push(" <option value=\"")
                    SelectDemo.push(data[i].DepartId)
                    SelectDemo.push("\">")
                    SelectDemo.push(data[i].DepartName)
                    SelectDemo.push("</option>")
                }
                $("#DepartId").html(SelectDemo.join(""))
            }
        })
        //当优惠价格改变时
        $("#RegistNoPrice").blur(function () {
            var RegistRePrice = $("#RegistRePrice").html()
            var RegistNoPrice = $("#RegistNoPrice").val();
            var RegistHasPrice = parseFloat(RegistRePrice) - parseFloat(RegistNoPrice);
            if (RegistHasPrice < 0) {
                $("#RegistHasPrice").html("请输入正确的价格").css("color", "red"); return;
            }
            $("#RegistHasPrice").html(RegistHasPrice).css("color", "#666666")
        })
    })
    //挂号类型改变时
    function RegistTypeChange(e) {
        $.ajax({
            type: "POST",
            url: "/RegistType/FnGetRegistTypeModel",
            data: {
                RegistTypeId: $(e).val()
            },
            success: function (data) {
                $("#RegistRePrice").html(data.RegistTypeSalePrice);
                var RegistNoPrice = $("#RegistNoPrice").val();
                var RegistHasPrice = parseFloat(data.RegistTypeSalePrice) - parseFloat(RegistNoPrice);
                $("#RegistHasPrice").html(RegistHasPrice);
            }
        })
    }
    //挂号科室改变时
    function DepartInfoChange(e) {
        $.ajax({//Ajax生成挂号类型下拉框
            type: "POST",
            url: "/RegistInfo/FnGetUserList",
            data: {
                DepartId: $(e).val()
            },
            success: function (data) {
                var SelectDemo = new Array();
                SelectDemo.push(" <option value=\"0\">不指定</option>")
                for (var i = 0; i < data.length; i++) {
                    SelectDemo.push("")
                    SelectDemo.push(" <option value=\"")
                    SelectDemo.push(data[i].UserId)
                    SelectDemo.push("\">")
                    SelectDemo.push(data[i].UserChineseName)
                    SelectDemo.push("</option>")
                }
                $("#UserIdOne").html(SelectDemo.join(""))
            }
        })
    }
    //选择挂号人改变时
    function RadioCheck(CkVal) {
        $.ajax({
            type: "POST",
            url: "/RegistInfo/FnGetRegistInfoModel",
            data: {
                RegistId: CkVal
            },
            success: function (data) {
                $("#RegistId").html(data.RegistId);
                $("#RegistChiName").val(data.RegistChiName);
                $("input[type=radio][name=RegistSex][value=" + data.RegistSex + "]")[0].checked = true
                $("#RegistSex").val(data.RegistSex);
                $("#RegistAge").val(data.RegistAge);
                $("#DepartId").val(data.DepartId);
                $.ajax({//Ajax生成挂号类型下拉框
                    type: "POST",
                    url: "/RegistInfo/FnGetUserList",
                    data: {
                        DepartId: data.DepartId
                    },
                    success: function (datas) {
                        var SelectDemo = new Array();
                        SelectDemo.push(" <option value=\"0\">不指定</option>")
                        for (var i = 0; i < datas.length; i++) {
                            SelectDemo.push("")
                            SelectDemo.push(" <option value=\"")
                            SelectDemo.push(datas[i].UserId)
                            SelectDemo.push("\">")
                            SelectDemo.push(datas[i].UserChineseName)
                            SelectDemo.push("</option>")
                        }
                        $("#UserIdOne").html(SelectDemo.join(""))
                        $("#UserIdOne").val(data.UserIdOne);
                        $("#RegistTypeId").val(data.RegistTypeId);
                        $("#RegistNoPrice").val(data.RegistNoPrice);
                        $("#RegistRePrice").html(data.RegistRePrice);
                        $("#RegistHasPrice").html(data.RegistHasPrice);
                    }
                })
                if (data.RegistState > 0) {
                    $("#RegistTypeId").attr("disabled", "disabled")
                    $("#RegistNoPrice").attr("disabled", "disabled")
                    $("#RegistRePrice").attr("disabled", "disabled")
                    $("#RegistHasPrice").attr("disabled", "disabled")
                    $("#DepartId").attr("disabled", "disabled")
                    $("#UserIdOne").attr("disabled", "disabled")
                    $("#RegistId").attr("disabled", "disabled")
                    $("#RegistChiName").attr("disabled", "disabled")
                    $("input[name=RegistSex]").attr("disabled", "disabled")
                    $("#RegistAge").attr("disabled", "disabled")
                    $("#DepartId").attr("disabled", "disabled")
                } else {
                    $("#RegistTypeId").removeAttr("disabled")
                    $("#RegistNoPrice").removeAttr("disabled")
                    $("#RegistRePrice").removeAttr("disabled")
                    $("#RegistHasPrice").removeAttr("disabled")
                    $("#DepartId").removeAttr("disabled")
                    $("#UserIdOne").removeAttr("disabled")
                    $("#DepartId").removeAttr("disabled")
                    $("#UserIdOne").removeAttr("disabled")
                    $("#RegistId").removeAttr("disabled")
                    $("#RegistChiName").removeAttr("disabled")
                    $("input[name=RegistSex]").removeAttr("disabled")
                    $("#RegistAge").removeAttr("disabled")
                    $("#DepartId").removeAttr("disabled")
                }
            }

        })
    }
</script>
<script>
    //显示页面的Ajax
    $(function () {
        //页面初次加载，调用AJAX，PageIndex 为1
        PageJump(1);

    })
    //分页数据加载方法
    function PageJump(PageIndex) {
        var PageSize = $("#PageSize").val();
        if (PageSize == "" || parseInt(PageSize) == 0 || PageSize == null) {
            PageSize = 10;
        }
        $.ajax({
            type: "POST",
            url: "/RegistInfo/FnRegistInfoPageList",
            data: {
                PageSize: PageSize,
                PageIndex: PageIndex,
            },
            success: function (data) {
                var TrDemo = new Array();
                var divDemo = new Array();
                for (var i = 0; i < data.PageList.length; i++) {
                    TrDemo.push()
                    TrDemo.push("<tr><td align=\"center\"> <input type=\"radio\" name=\"radioch\" onclick=\"RadioCheck(")
                    TrDemo.push(data.PageList[i].RegistId)
                    TrDemo.push(")\" value=\"1\" /></td><td align=\"center\"> ")
                    if (data.PageList[i].RegistState == 0) {
                        TrDemo.push("待诊")
                    }
                    if (data.PageList[i].RegistState == 1) {
                        TrDemo.push("接诊中")
                    }
                    if (data.PageList[i].RegistState == 2) {
                        TrDemo.push("已诊")
                    }
                    if (data.PageList[i].RegistState == 3) {
                        TrDemo.push("已过期")
                    }
                    TrDemo.push("</td><td align=\"center\"> ")
                    TrDemo.push(data.PageList[i].RegistChiName)
                    TrDemo.push("</td><td align=\"center\"> ")
                    if (data.PageList[i].RegistSex == 1) {
                        TrDemo.push("男")
                    }
                    if (data.PageList[i].RegistSex == 2) {
                        TrDemo.push("女")
                    }
                    TrDemo.push("</td><td align=\"center\"> ")
                    TrDemo.push(data.PageList[i].RegistAge)
                    TrDemo.push("岁</td><td align=\"center\"> ")
                    TrDemo.push(data.PageList[i].DepartName)
                    TrDemo.push("</td><td align=\"center\"> ")
                    TrDemo.push(data.PageList[i].UserChineseNameOne)
                    TrDemo.push("</td><td align=\"center\"> ")
                    TrDemo.push(data.PageList[i].UserChineseNameTwo)
                    TrDemo.push("</td><td align=\"left\"> ")
                    TrDemo.push(ChangeDateFormat(data.PageList[i].RegistTime))
                    TrDemo.push("</td>")
                    TrDemo.push("<tr>")
                }
                $("#tbodyShow").html(TrDemo.join(""));

                //调用分页索引条
                PageDemoSuccess(divDemo, data);
                $(".divPage").html(divDemo.join(""));
            }
        })
    }
    //分页索引条加载方法
    function PageDemoSuccess(divDemo, data) {
        divDemo.push("<nav>")
        divDemo.push("<ul class=\"pagination\">")
        divDemo.push("<li>")
        divDemo.push(" <span>每页");
        divDemo.push("<input type=\"text\" style=\"width:40px;height:5px\"class=\"inpMain\" id=\"PageSize\" value=\"")
        divDemo.push(data.PageSize);
        divDemo.push("\" placeholder=\"\" />");
        divDemo.push(" 条</span></li>")
        divDemo.push("<li><span>共" + data.PageCount + "页，第" + data.PageIndex + "页，共" + data.PageNum + "条</span></li>")
        divDemo.push("<li><span onclick=\"PageJump(1)\" aria-label=\"Previous\"><span aria-hidden=\"true\">首页</span></span></li>")
        if (data.PageIndex <= 1) {
            divDemo.push("<li class=\"disabled\"><span onclick=\"PageJump(1)\">上一页</span></li>")
        }
        else {
            divDemo.push("<li><span onclick=\"PageJump(" + (data.PageIndex - 1) + ")\">上一页</span></li>")
        }
        for (var i = 0; i < data.PageCount; i++) {
            if (data.PageCount > 8) {
                if (data.PageIndex == 1) {
                    if (i <= 3) {
                        if (i == 3) {
                            LiNoPush(divDemo);
                        } else {
                            LiJumpPush(data.PageIndex, i, divDemo)
                        }
                    } else {
                        break;
                    }
                }
                else if (data.PageIndex == data.PageCount) {

                    if (i >= (data.PageCount - 4)) {
                        if (i == data.PageCount - 4) {
                            LiNoPush(divDemo);
                        } else {
                            LiJumpPush(data.PageIndex, i, divDemo)
                        }
                    }
                    else {
                        continue;
                    }
                } else {
                    if ((data.PageIndex - 3) <= i && i <= (data.PageIndex + 1)) {
                        if (data.PageIndex - 3 == i) {
                            LiNoPush(divDemo);
                        } else if (data.PageIndex + 1 == i) {
                            LiNoPush(divDemo);
                        } else {
                            LiJumpPush(data.PageIndex, i, divDemo)
                        }
                    } else {
                        continue;
                    }
                }
            } else {
                LiJumpPush(data.PageIndex, i, divDemo)
            }
        }
        if (data.PageIndex == data.PageCount) {
            divDemo.push("<li class=\"disabled\"><span onclick=\"PageJump(" + data.PageCount + ")\">下一页</span></li>")
        }
        else {
            divDemo.push("<li><span onclick=\"PageJump(" + (data.PageIndex + 1) + ")\">下一页</span></li>")
        }
        divDemo.push(" <li><span onclick=\"PageJump(" + data.PageCount + ")\" aria-label=\"Next\"><span aria-hidden=\"true\">尾页</span></span></li>")
        divDemo.push("</ul>")
        divDemo.push("</nav>")
    }
    //分页链接跳转方法
    function LiJumpPush(PageIndex, Num, Demo) {
        Demo.push("<li ")
        if (PageIndex == (Num + 1)) {
            Demo.push(" class=\"active\"")
        }
        Demo.push("><span onclick=\"PageJump(" + (Num + 1) + ")\">" + (Num + 1) + "</span></li>")
    }
    //省略号加载方法
    function LiNoPush(Demo) {
        Demo.push("<li><span>...</span></li>")
    }
</script>